package Presentation;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import Logic.Rank;

public class MyRankPanel extends JPanel{
	
	public MyRankPanel(final MainFrame main, final Rank rank){		
		super();
		setLayout(null);
		setSize(350,100);
		setBorder(new LineBorder(Color.black));
		
		JLabel headerL;
		JButton btn;
		if (rank == null){
			headerL = new MyLabel("You didn't ranked this movie yet...",300,30,25,10);
			btn = new MyButton("Rank It!",100,30,125,50);
			btn.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
					String[] ranks = {"1", "2", "3","4", "5", "6","7", "8", "9","10"};
					String s = (String)JOptionPane.showInputDialog(
					                    main,"Choose Your Rank:","Rank It!"
					                    ,JOptionPane.PLAIN_MESSAGE,null,ranks,"5");
					if (s != null){
						int rank = Integer.valueOf(s);					
						main.addRank(rank);
					}
				}
			});
		}
			
		else{
			headerL = new MyLabel("You ranked this movie : " + rank.getRank(),300,30,25,10);
			btn = new MyButton("Change your rank",200,30,75,50);
			btn.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
					String[] ranks = {"1", "2", "3","4", "5", "6","7", "8", "9","10"};
					String s = (String)JOptionPane.showInputDialog(
					                    main,"Choose Your Rank:","Rank It!"
					                    ,JOptionPane.PLAIN_MESSAGE,null,ranks,"5");
					if (s != null){
						int newRank = Integer.valueOf(s);
						rank.setRank(newRank);
						main.refreshMyRanks();
					}
				}
			});
		}
		
		headerL.setHorizontalAlignment(SwingConstants.CENTER);
		headerL.setVerticalAlignment(SwingConstants.CENTER);
		headerL.setFont(new Font("Arial",Font.BOLD,16));		
		add(headerL);
		add(btn);
			
			
	}

}
